package com.servlet.listener;

import com.servlet.bean.User;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.ArrayList;
import java.util.List;

/**
 * @Title: MyServletContextListener
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2023/12/26 15:24
 */
@WebListener
public class MyServletContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext();
        List<User> list = new ArrayList<>();
        servletContext.setAttribute("online",list);


    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext();
        servletContext.removeAttribute("online");
    }
}
